package ro.isdc.navigator.retriever.jdbc.strategy;

/**
 * SQLServer 2005 strategy for computing the paginated SQL.
 * 
 * @author Andrei Chirila / ISDC! Romania
 * @version 1.0
 * @date Jul 9, 2009
 */
public class SQLServer2005ComputePaginatedSQLStrategy extends AbstractComputePaginatedSQLStrategy {
  
  /**
   * {@inheritDoc}
   */
  protected String buildPaginatedSQL(final String SQL, final SQLType sqlType) {
    StringBuffer buffer = new StringBuffer(
        "select * from ( select row_number() over (order by current_timestamp) as rownum_, row_.* from ( ");
    buffer.append(SQL);
    buffer.append(" ) as row_) as rrow_ where");
    if (SQLType.INDEXED == sqlType) {
      buffer.append(" rownum_ > ?  and rownum_ <= ?");
    } else {
      buffer.append(" rownum_ > :start and rownum_ <= :end");
    }
    buffer.append(" order by rownum_");
    return buffer.toString();
  }

}
